/**
 * This software was produced for the U. S. Government
 * under Contract No. FA8721-09-C-0002, and is
 * subject to the Rights in Noncommercial Computer Software
 * and Noncommercial Computer Software Documentation Clause
 * (DFARS) 252.227-7014 (JUN 1995)
 * 
 * (c) 2009 The MITRE Corporation. All Rights Reserved.
 *
 * SPMIF to OPNET Translator
 * Author: EWALTERS
 * Created: 12:30:22 PM, May 23, 2008
 * MITRE Corporation
 */
package com.mitre.spmif2opnet.analysis.ast;

/*
 * Represents conversion between units 
 */
public enum ServiceUnitType {
	MILLI_SEC {
		public double normalize(double d) {
			return d / 1000.0;
		}
		public boolean validString(String s) {
			return s.equals("ms");
		}
	},
	MICRO_SEC {		
		public double normalize(double d) {
			return d / 1000000.0;
		}
		public boolean validString(String s) {
			return s.equals("us");
		}
	},
	SEC {
		public double normalize(double d) {
			return d;
		}
		public boolean validString(String s) {
			return s.equals("s");
		}			
	};
	// Normalize values to seconds
	public abstract double normalize(double d);
	protected abstract boolean validString(String s);
	public static ServiceUnitType fromString(String s) {
		for (ServiceUnitType unit : ServiceUnitType.values()) {
			if (unit.validString(s)) {
				return unit;
			}
		}
		return SEC; // default - raw seconds
	}
}